unit MtPanel;

interface

uses Windows, Classes, Controls, ExtCtrls, Graphics;

type
  TMtShadowPanel = class(TPanel)
  private
    FLightColor: TColor;
    FShadowColor: TColor;
    procedure SetLightColor(const Value: TColor);
    procedure SetShadowColor(const Value: TColor);
  protected
    procedure Paint; override;
  published
    property LightColor: TColor read FLightColor write SetLightColor default clBtnHighlight;
    property ShadowColor: TColor read FShadowColor write SetShadowColor default clBtnShadow;
  public
    constructor Create(AOwner: TComponent); override;
  end;

//  TMtRoundedTanel = class(TPanel)
//
//  end;

implementation

{ TMtShadowPanel }

constructor TMtShadowPanel.Create(AOwner: TComponent);
begin
  inherited;
  FLightColor := clBtnHighlight;
  FShadowColor := clBtnShadow;
end;

procedure TMtShadowPanel.Paint;
const
  Alignments: array[TAlignment] of Longint = (DT_LEFT, DT_RIGHT, DT_CENTER);
var
  Rect: TRect;
  TopColor, BottomColor: TColor;
  FontHeight: Integer;
  Flags: Longint;

  procedure AdjustColors(Bevel: TPanelBevel);
  begin
    TopColor := FLightColor;
    if Bevel = bvLowered then
      TopColor := FShadowColor;

    BottomColor := FShadowColor;
    if Bevel = bvLowered then
      BottomColor := FLightColor;
  end;

begin
  Rect := GetClientRect;
  if BevelOuter <> bvNone then
  begin
    AdjustColors(BevelOuter);
    Frame3D(Canvas, Rect, TopColor, BottomColor, BevelWidth);
  end;
  Frame3D(Canvas, Rect, Color, Color, BorderWidth);    //use the Color property value to get the background color.
  if BevelInner <> bvNone then
  begin
    AdjustColors(BevelInner);
    Frame3D(Canvas, Rect, TopColor, BottomColor, BevelWidth);
  end;
  with Canvas do
  begin
    Brush.Color := Color;
    FillRect(Rect);
    Brush.Style := bsClear;
    Font := Self.Font;
    FontHeight := TextHeight('W');
    with Rect do
    begin
      Top := ((Bottom + Top) - FontHeight) div 2;
      Bottom := Top + FontHeight;
    end;
    Flags := DT_EXPANDTABS or DT_VCENTER or Alignments[Alignment];
    Flags := DrawTextBiDiModeFlags(Flags);
    DrawText(Handle, PChar(Caption), -1, Rect, Flags);
  end;
end;

procedure TMtShadowPanel.SetLightColor(const Value: TColor);
begin
  if Value <> FLightColor then
  begin
    FLightColor := Value;
    Repaint;
  end;
end;

procedure TMtShadowPanel.SetShadowColor(const Value: TColor);
begin
  if Value <> FShadowColor then
  begin
    FShadowColor := Value;
    Repaint;
  end;
end;

end.
